package nowcoder;

import java.util.Scanner;

public class 最长公共子串 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.nextLine();
        String s2 = scanner.nextLine();
        System.out.println(maxSubStr(s1, s2));
    }

    /**
     * 循环法
     * 贪心法，先试最长的，试到直接返回
     * @param s1
     * @param s2
     * @return
     */
    public static int maxSubStr(String s1, String s2) {
        String minStr = s1.length() < s2.length() ? s1 : s2;
        String maxStr = s1.length() < s2.length() ? s2 : s1;

        //从最长开始试，逐渐减少期望长度
        for (int maxCommonLength = minStr.length(); maxCommonLength >= 1; maxCommonLength--) {
            //移动定长的范围区间
            for (int left = 0; left <= minStr.length() - maxCommonLength; left++) {
                int right = left + maxCommonLength;
                if (maxStr.contains(minStr.substring(left, right))) {
                    return right - left;
                }
            }
        }
        return 0;
    }

    /**
     * 二维数组法
     * @param s1
     * @param s2
     * @return
     */
    public static int maxSubStr2(String s1, String s2) {
        return 0;
    }
}
